/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: UserDetailsServiceImpl
 * Author:   kadibeieun
 * Date:     2019/8/8 16:20
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.mengde.service.impl;

import com.mengde.pojo.JwtUser;
import com.mengde.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * 〈一句话功能简述〉<br> 
 * 〈使用springSecurity需要实现UserDetailsService接口供权限框架调用，
 * 该方法只需要实现一个方法就可以了，那就是根据用户名去获取用户，
 * 那就是上面repository定义的方法了，这里直接调用了〉
 *
 * @author kadibeieun
 * @create 2019/8/8
 * @since 1.0.0
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private UserRepository userRepository;

    /**
     * 自定义验证用户的实现
     * @param username
     * @return
     * @throws UsernameNotFoundException
     */
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return new JwtUser(userRepository.findByUsername(username));
    }
}